package com.bingxue.edu.teacher.controller;

import com.bingxue.edu.framework.common.model.Response;
import com.bingxue.edu.management.auth.EmployeeAuthUtil;
import com.bingxue.edu.management.education.model.entity.ClassStat;
import com.bingxue.edu.management.report.model.resp.ClassStatResp;
import com.bingxue.edu.teacher.model.query.TeacherClassStatQuery;
import com.bingxue.edu.teacher.model.resp.TeacherClassStatSummaryResp;
import com.bingxue.edu.teacher.service.TeacherClassStatService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "教师端小程序-三率接口")
@RestController
@RequestMapping("/t/class/stat")
@RequiredArgsConstructor
public class TeacherClassStatController {

    private final TeacherClassStatService teacherClassStatService;

    @Operation(summary = "查询三率列表")
    @GetMapping("/list")
    public Response<List<ClassStatResp>> getClassStatList(TeacherClassStatQuery query) {
        String currentUserId = EmployeeAuthUtil.getCurrentUserId();
        if (EmployeeAuthUtil.isAssistTeacher()) {
            query.setAssistTeacherId(currentUserId);
        } else {
            query.setLeadTeacherId(currentUserId);
        }
        List<ClassStatResp> classStatList = teacherClassStatService.getClassStatList(query);
        return Response.success(classStatList);
    }

    @Operation(summary = "查询班级三率")
    @GetMapping("/class/{id}")
    public Response<ClassStat> getClassStatByClassId(@PathVariable String id) {
        return Response.success(teacherClassStatService.getClassStatByClassId(id));
    }

    @Operation(summary = "查询三率总览")
    @GetMapping("/summary")
    public Response<List<TeacherClassStatSummaryResp>> getTeacherClassStatSummary(TeacherClassStatQuery query) {
        String currentUserId = EmployeeAuthUtil.getCurrentUserId();
        if (EmployeeAuthUtil.isAssistTeacher()) {
            query.setAssistTeacherId(currentUserId);
        } else {
            query.setLeadTeacherId(currentUserId);
        }
        List<TeacherClassStatSummaryResp> teacherClassRateTotal = teacherClassStatService.getTeacherClassStatSummary(query);
        return Response.success(teacherClassRateTotal);
    }

}
